package com.kaifamiao.www.ioDemo.do0921;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class BufferedInputStreamDemo {
    public static void main(String[] args) {
        String path = "E:\\kaifamiao\\workspace\\idea--space\\io\\buffer-input.txt";
        try (FileInputStream fis = new FileInputStream(path);){
            //markSupported 判断某个流是否支持 标记/重置 操作:
            System.out.println(fis.markSupported());
            BufferedInputStream bis = new BufferedInputStream(fis);
            System.out.println(bis.markSupported());

            //声明一个变量表示是否已经做过标记
            boolean marked = false;
           int c;
           while ((c = bis.read())!=-1){
               char ch = (char) c;
               System.out.print(ch);
               if (ch =='m'){
                   bis.mark(0);
                   marked = true;
               }
           }
            System.out.println("这是一条分割线");
           if (marked){
               bis.reset();
           }
           while ((c = bis.read())!=-1){
               char ch = (char) c;
               System.out.print(ch);
           }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
